package com.zhongke.cotrun.mapper;


import com.zhongke.cotrun.model.pojo.IntegralRecord;
import com.zhongke.cotrun.model.pojo.IntegralRecordVo;
import org.apache.ibatis.annotations.*;


import java.util.List;

//积分规则
public interface IntegralRecordMapper {
    /**
     * 新建积分规则
     *
     * @param integralRecord
     * @return
     */
    @Options(useGeneratedKeys = true, keyProperty = "integralRecordId")
    @Insert("INSERT INTO `integral_record` (`interal_name_id`, `integral_name`, `state`, `remark`, `link_user_id`, `create_time`, `update_time`, `perpetual`, `start_time`, `finish_time`,`rank_one`,`rank_two`) VALUES " +
            "(#{interalNameId}, #{integralName}, 1, #{remark}, #{linkUserId}, NOW(), NOW(), #{perpetual}, #{startTime}, #{finishTime},#{rankOne},#{rankTwo})")
//    @Insert("INSERT INTO `integral_record` (`interal_name_id`, `state`, `remark`, `link_user_id`, `create_time`, `update_time`, `perpetual`, `start_time`, `finish_time`, `integral_value`,`grade`,`user_type`) VALUES (#{interalNameId}, 1, #{remark}, #{linkUserId}, NOW(), NOW(), #{perpetual}, #{startTime}, #{finishTime}, #{integralValue},#{grade},#{userType})")
    public boolean insertIntegralRecord(IntegralRecord integralRecord);

//    支持积分状态筛选,支持积分ID、积分名称、积分状态、备注(有字数展示限制)、操作人、最后更新时间、操作.

    /**
     * 根据条件搜索积分规则
     *
     * @param integralRecord
     * @return
     */
    public List<IntegralRecordVo> selectAllIntegralRecord(IntegralRecord integralRecord);

    /**
     * 根据id查看
     *
     * @param integralRecordId
     * @return
     */
    @Select("SELECT * from integral_record WHERE integral_record_id=#{integralRecordId}")

    @Results({
            @Result(id = true, property = "integralRecordId", column = "integral_record_id"),
            @Result(property = "interalNameId", column = "interal_name_id"),
            @Result(property = "integralName", column = "integral_name"),
            @Result(property = "state", column = "state"),
            @Result(property = "remark", column = "remark"),
            @Result(property = "linkUserId", column = "linkUser_id"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "startTime", column = "start_time"),
            @Result(property = "finishTime", column = "finish_time"),
            @Result(property = "perpetual", column = "perpetual"),
            @Result(property = "rankOne", column = "rank_one"),
            @Result(property = "rankTwo", column = "rank_two"),
            @Result(property = "membershipValues", column = "integral_record_id", many = @Many(
                    select = "com.zhongke.cotrun.mapper.MembershipValuesMapper.selectAllMembershipValuesByOfIntegralRecordId"
            ))


    })
    public IntegralRecordVo selectIntegralRecordById(Integer integralRecordId);

    /**
     * 跟新
     *
     * @param integralRecord
     * @return
     */

    public boolean updateIntegralRecord(IntegralRecord integralRecord);

    /**
     * 根据类型id查询积分规则
     *
     * @param integralNameId
     * @return
     */
    @Select("SELECT * from integral_record WHERE  interal_name_id=#{integralNameId} AND state=1")
    @Results({
            @Result(id = true, property = "integralRecordId", column = "integral_record_id"),
            @Result(property = "interalNameId", column = "interal_name_id"),
            @Result(property = "integralName", column = "integral_name"),
            @Result(property = "state", column = "state"),
            @Result(property = "remark", column = "remark"),
            @Result(property = "linkUserId", column = "linkUser_id"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "startTime", column = "start_time"),
            @Result(property = "finishTime", column = "finish_time"),
            @Result(property = "perpetual", column = "perpetual"),
            @Result(property = "rankOne", column = "rank_one"),
            @Result(property = "rankTwo", column = "rank_two"),
            @Result(property = "membershipValues", column = "integral_record_id", many = @Many(
                    select = "com.zhongke.cotrun.mapper.MembershipValuesMapper.selectAllMembershipValuesByOfIntegralRecordId"
            ))


    })
    public IntegralRecordVo selectIntegralRecordByIntegralNameId(Integer integralNameId);

    /**
     * 根据积分名字查询
     *
     * @param integralName
     * @return
     */
    @Select("SELECT * from integral_record WHERE  integral_name=#{integralName} AND state=1")
    @Results({
            @Result(id = true, property = "integralRecordId", column = "integral_record_id"),
            @Result(property = "interalNameId", column = "interal_name_id"),
            @Result(property = "integralName", column = "integral_name"),
            @Result(property = "state", column = "state"),
            @Result(property = "remark", column = "remark"),
            @Result(property = "linkUserId", column = "linkUser_id"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "startTime", column = "start_time"),
            @Result(property = "finishTime", column = "finish_time"),
            @Result(property = "perpetual", column = "perpetual"),
            @Result(property = "rankOne", column = "rank_one"),
            @Result(property = "rankTwo", column = "rank_two"),
            @Result(property = "membershipValues", column = "integral_record_id", many = @Many(
                    select = "com.zhongke.cotrun.mapper.MembershipValuesMapper.selectAllMembershipValuesByOfIntegralRecordId"
            ))


    })
    public IntegralRecordVo selectIntegralRecordByIntegralName(String integralName);


    /**
     * 查询自己的权益
     * @param integralRecordVo
     * @return
     */

     public List<IntegralRecordVo> selectRights(IntegralRecordVo integralRecordVo);
}
